<?php
/* 
 * To change this template, choose Tools | Templates
 * and open the template in the editor.
 */
class Custom_View_Helper_FlashMessenger extends Zend_View_Helper_Abstract
{
	public function flashMessenger ($width = null)
    {
		$flash = Zend_Controller_Action_HelperBroker::getStaticHelper('FlashMessenger');

		#for message
		$message = '';
		
		if($flash->getCurrentMessages())
		{
			foreach($flash->getCurrentMessages() as $key => $msg)
			{
				$message[key($msg)][] = $msg[key($msg)];
			}

			$flash->clearCurrentMessages();
		}
		else if($flash->getMessages())
		{
			foreach($flash->getMessages() as $key => $msg)
			{
				$message[key($msg)][] = $msg[key($msg)];
			}
		}

		$str_msg = '';
		$style = '';

		if($width) $style = "style='width:".$width."px'";

		if(is_array($message))
		{
			foreach($message as $key => $arr_msg)
			{
                $key = ($key == 'error')?'errormsg':$key;

				$str_msg .= '<div '.$style.' class="message '.$key.'">';
				$str_msg .=	'<p>';

				foreach($arr_msg as $msg)
				{
						$str_msg .= $msg. "<br/>";
				}
				$str_msg .= '</p>';
				$str_msg .= '</div>';
			}
	   }

	   return $str_msg;
	}
}
?>
